from django.db import models
from myapp.models import User,Merchant

# Create your models here.


# 房间表
class ChatRoomModel(models.Model):
    room_name = models.CharField('房间名', max_length=10)
    # auto_now_add = True   创建时自动添加的时间
    created_time = models.DateTimeField("创建时间", auto_now_add=True)
    # auto_now = Ture   更新数据时  修改时间
    updated_time = models.DateTimeField("更新时间", auto_now=True)

    class Meta:
        db_table = 'tb_room'
        verbose_name_plural = "房间表"

    def __str__(self):
        return self.room_name


# 聊天信息表
class ChatMessageModel(models.Model):
    message = models.CharField('消息内容', max_length=300)
    room = models.ForeignKey(ChatRoomModel, on_delete=models.CASCADE, verbose_name='房间')
    user = models.ForeignKey(User, on_delete=models.CASCADE, default="", verbose_name='用户id')
    merchant = models.ForeignKey(Merchant, on_delete=models.CASCADE, default="", verbose_name="商家id")
    types = models.SmallIntegerField(choices=((0, '顾客'), (1, '商家'),),verbose_name='发送人身份' )
    class Meta:
        db_table = 'tb_chatMessage'
        verbose_name_plural = "聊天信息表"

    def __str__(self):
        return self.message
